
package com.bear.cmcc.NetTestHTTP.ui.activity;

import com.bear.cmcc.NetTestHTTP.NetworkTestApp;
import com.bear.cmcc.NetTestHTTP.R;
import com.bear.cmcc.NetTestHTTP.component.CityBean;
import com.bear.cmcc.NetTestHTTP.component.CountryBean;
import com.bear.cmcc.NetTestHTTP.component.json.respond.GetNetDataReturnInfoRespond;
import com.bear.cmcc.NetTestHTTP.component.json.respond.NetDataDescriInfoRespond;
import com.bear.cmcc.NetTestHTTP.constant.HttpConstant;
import com.bear.cmcc.NetTestHTTP.constant.LocationConstant;
import com.bear.cmcc.NetTestHTTP.constant.MyCommonConstant;
import com.bear.cmcc.NetTestHTTP.httpUtil.HttpUtil;
import com.bear.cmcc.NetTestHTTP.ui.adapter.CitySortAdapter;
import com.bear.cmcc.NetTestHTTP.ui.view.HVListView;
import com.bear.cmcc.NetTestHTTP.ui.view.LoadingDialog;
import com.bear.cmcc.NetTestHTTP.util.CountryUtil;
import com.bear.cmcc.NetTestHTTP.util.MyCommonUtil;
import com.bear.cmcc.NetTestHTTP.util.SortCityIntSpeed;
import com.bear.cmcc.NetTestHTTP.util.SortCityStringSpeed;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CityInfoActivity extends AbstractActivity {

    private LinearLayout lyStretch, ly_first;

    private CheckBox cbInfoSelect, cbSelect;

    private TextView tvDropRate, tvSignal, tvComplete;

    private boolean is2gtd, isfre, isdrop, isSignal, isComplete;

    private Button btnNetTD;

    private Button btnNet2G;

    private TextView tvTD2G;

    private boolean isShare, isShareData;

    private String provinceName;

    private CountryBean mCountryBean;

    private List<CityBean> itemlist = new ArrayList<CityBean>();

    private List<CityBean> cityListTD;

    private List<CityBean> cityList2G;

    private CitySortAdapter cityAdapter;

    private TextView allInfoTV, firstcontentTV;

    String showAllInfo;

    /**
     * 当前手机所在的城市，通过百度定位实现。
     */
    private String currentCityName = null;

    private HVListView listViewRank;

    private boolean isShowTdData = true;

    private int pos = -1;

    private String provinceCode;

    int refresh = 3;

    int showLoadDialog = 4;

    private LoadingDialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        provinceName = getIntent().getStringExtra("provinceName");
        loadBottomBar();
        choseBottomItemIndex(MyCommonConstant.COUNTRY_ACTIVITY_INDEX);
        setTitle(provinceName);
        setContentView(R.layout.activity_city);
        layoutInit();
        provinceCode = getIntent().getStringExtra(MyCommonConstant.PROVINCE_CODE);
        dialog = new LoadingDialog(this);
        dataInit();
    }

    @Override
    protected void onStart() {
        choseBottomItemIndex(MyCommonConstant.COUNTRY_ACTIVITY_INDEX);
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setCurrentProviceHigltShow(null);
    }

    private void layoutInit() {
        setCloseButton(R.string.top_back, onclick);
        setShareButton(onclick);

        cbInfoSelect = (CheckBox) findViewById(R.id.cbInfoSelect);
        cbInfoSelect.setOnCheckedChangeListener(onCheckedListener);
        cbInfoSelect.setChecked(true);

        // tvTDValue = (TextView) findViewById(R.id.tvTDValue);
        // tv2GValue = (TextView) findViewById(R.id.tv2GValue);
        btnNetTD = (Button) findViewById(R.id.btnNetTD1);
        btnNetTD.setBackgroundResource(R.drawable.tabhead_actived_bak);
        btnNetTD.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                setListViewData(true);

            }
        });
        btnNet2G = (Button) findViewById(R.id.btnNet2G1);
        btnNet2G.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                setListViewData(false);

            }
        });

        cbSelect = (CheckBox) findViewById(R.id.cbSelect);
        cbSelect.setOnCheckedChangeListener(onCheckedListener);
        tvTD2G = (TextView) findViewById(R.id.tvTD2G);
        // tvFrequency = (TextView) findViewById(R.id.tvFrequency);
        tvDropRate = (TextView) findViewById(R.id.tvDropRate);
        tvSignal = (TextView) findViewById(R.id.tvSignal);
        tvComplete = (TextView) findViewById(R.id.tvComplete);
        // tvFrequency.setText(getString(R.string.frequency) +
        // getString(R.string.sortdown));
        // tvDropRate.setText(getString(R.string.city_top_slide_drop_rate)
        // + getString(R.string.sortdown));
        // tvSignal.setText(getString(R.string.city_top_slide_signal) +
        // getString(R.string.sortdown));
        tvTD2G.setOnClickListener(onclick);
        // tvFrequency.setOnClickListener(onclick);
        tvDropRate.setOnClickListener(onclick);
        tvSignal.setOnClickListener(onclick);
        tvComplete.setOnClickListener(onclick);

        listViewRank = (HVListView) findViewById(R.id.listViewRank);
        listViewRank.setmListHead((LinearLayout) findViewById(R.id.lyInfo));
        listViewRank.setOnItemClickListener(onItemClickListener);
        listViewRank.setOnScrollListener(scrollListener);
        cityAdapter = new CitySortAdapter(this, itemlist, listViewRank);
        listViewRank.setAdapter(cityAdapter);

        lyStretch = (LinearLayout) findViewById(R.id.lyStretch);
        ((CheckBox) findViewById(R.id.cbStretch)).setOnCheckedChangeListener(onCheckedListener);
        ((LinearLayout) findViewById(R.id.ly_layout)).setOnClickListener(onClickListener);

        ly_first = (LinearLayout) findViewById(R.id.ly_first);
        allInfoTV = (TextView) findViewById(R.id.allcontent);
        firstcontentTV = (TextView) findViewById(R.id.firstcontent);
        firstcontentTV.setOnClickListener(onClickListener);
        allInfoTV.setOnClickListener(onClickListener);
    }

    private void shareLayout() {
        if (isShare) {
            cbInfoSelect.setVisibility(View.VISIBLE);
            cbSelect.setVisibility(View.VISIBLE);
            cityAdapter.setSelect(isShare);
        } else {
            cbInfoSelect.setVisibility(View.GONE);
            cbSelect.setVisibility(View.GONE);
            cityAdapter.setSelect(isShare);
        }
    }

    private void dataInit() {
        isShare = false;
        shareLayout();
        getData();
    }

    private void setLayoutData() {
        if (showAllInfo != null) {
            allInfoTV.setText(Html.fromHtml(showAllInfo));
            firstcontentTV.setText(Html.fromHtml(showAllInfo));
        }
    }

    private void initializeShowAllInfo() {
        GetNetDataReturnInfoRespond info = HttpUtil.getRegionNetInfo(CityInfoActivity.this,
                HttpConstant.PROVINCE, provinceCode);
        int allDevice = 0;
        int cellNumber = 0;
        int cityNumber = 0;
        int gridNumber = 0;
        int randTd = 0;
        int rand2G = 0;
        String speedTd = "0";
        String speed2G = "0";
        if (info != null && info.getErrorcode() == HttpConstant.CODE_SUCCESS) {
            NetDataDescriInfoRespond respond = info.getData();
            if (respond != null) {
                allDevice = respond.getOnline2G() + respond.getOnlineTD();
                cellNumber = respond.getCellNumber();
                cityNumber = respond.getCityNumber();
                speedTd = respond.getAverageSpeedTD();
                speed2G = respond.getAverageSpeed2G();
                randTd = respond.getRandTd();
                rand2G = respond.getRand2G();
                gridNumber = respond.getGridNumber();
            }
        }

        showAllInfo = "&nbsp;&nbsp;&nbsp;&nbsp;"
                + CountryUtil.getSpecialGrayStr(this, provinceName
                        + getString(R.string.current_device_num))
                + CountryUtil.getSpecialWhiteStr(this, allDevice + "")
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.unit))
                + CountryUtil.getSpecialWhiteStr(this, "" + cityNumber)
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.current_city_city))
                + CountryUtil.getSpecialWhiteStr(this, gridNumber + "")
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.current_city_wg))
                + CountryUtil.getSpecialWhiteStr(this, cellNumber + "")
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.current_city_xq))
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.current_city_td)
                        + getString(R.string.current_city_qgpm))
                + CountryUtil.getSpecialWhiteStr(this, "" + randTd)
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.current_city_w))
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.current_city_pjsl))
                + CountryUtil.getSpecialWhiteStr(this, "" + speedTd)
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.speedunit))
                // +CountryUtil.getSpecialGrayStr(this,
                // getString(R.string.yhbs))+CountryUtil.getSpecialWhiteStr(this,
                // getString(R.string.yhbdvalue1))
                // +CountryUtil.getSpecialGrayStr(this, getString(R.string.qsd))
                // + CountryUtil.getSpecialWhiteStr(this,
                // getString(R.string.qsvalue1))+
                // CountryUtil.getSpecialGrayStr(this, getString(R.string.yhbe))
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.current_city_2G)
                        + getString(R.string.current_city_qgpm))
                + CountryUtil.getSpecialWhiteStr(this, "" + rand2G)
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.current_city_w))
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.current_city_pjsl))
                + CountryUtil.getSpecialWhiteStr(this, "" + speed2G)
                + CountryUtil.getSpecialGrayStr(this, getString(R.string.speedunit));
        // +CountryUtil.getSpecialGrayStr(this,
        // getString(R.string.yhbs))+CountryUtil.getSpecialWhiteStr(this,
        // getString(R.string.yhbdvalue2));
        // +CountryUtil.getSpecialGrayStr(this, getString(R.string.qsd)) +
        // CountryUtil.getSpecialWhiteStr(this, getString(R.string.qsvalue2))+
        // CountryUtil.getSpecialGrayStr(this, getString(R.string.yhbe))
        // + "<br/>" + CountryUtil.getSpecialGrayStr(this, provinceName +
        // getString(R.string.cityStretchTitleTDWG)) ;
        // if(provinceName.equals("福建"))
        // {
        // showAllInfo = showAllInfo +CountryUtil.getSpecialGrayStr(this,
        // getString(R.string.citystretchContentTD1))+CountryUtil.getSpecialGrayStr(this,
        // getString(R.string.citystretchContentTD2))+CountryUtil.getSpecialGrayStr(this,
        // getString(R.string.citystretchContentTD3));
        // }
        // else
        // {
        // showAllInfo = showAllInfo +CountryUtil.getSpecialGrayStr(this,
        // getString(R.string.citystretchContentNO));
        // }
    }

    private void setListViewData(boolean isTD) {
        if (itemlist != null) {
            itemlist.clear();
            isShowTdData = isTD;
            if (isTD) {
                btnNetTD.setBackgroundResource(R.drawable.tabhead_actived_bak);
                btnNet2G.setBackgroundResource(R.drawable.tabtail_normal_bak);

                tvTD2G.setText(getString(R.string.city_top_fix_speed) + getString(R.string.sortup));
                if (cityListTD != null) {
                    itemlist.addAll(cityListTD);

                    Collections.sort(itemlist, new Comparator<CityBean>() {

                        @Override
                        public int compare(CityBean lhs, CityBean rhs) {
                            int result = -1 * (lhs.getDownSpeed() - rhs.getDownSpeed());// 降序
                            return result;
                        }

                    });
                }
            } else {

                btnNetTD.setBackgroundResource(R.drawable.tabhead_normal_bak);
                btnNet2G.setBackgroundResource(R.drawable.tabtail_actived_bak);

                tvTD2G.setText(getString(R.string.city_top_fix_speed) + getString(R.string.sortup));
                if (cityList2G != null) {
                    if (itemlist != null)
                        itemlist.clear();
                    itemlist.addAll(cityList2G);

                    Collections.sort(itemlist, new Comparator<CityBean>() {

                        @Override
                        public int compare(CityBean lhs, CityBean rhs) {
                            int result = -1 * (lhs.getDownSpeed() - rhs.getDownSpeed());// 降序
                            return result;
                        }

                    });
                }

            }
            cityAdapter.notifyDataSetChanged(itemlist.size(), isTD, pos);
            setCurrentProviceHigltShow(null);
        }
    }

    private void getData() {
        new Thread() {
            public void run() {
                handler.sendEmptyMessage(showLoadDialog);

                initializeShowAllInfo();
                cityList2G = HttpUtil.getProvinceFtpInfoAdapter(CityInfoActivity.this,
                        provinceCode, MyCommonConstant.NET_TYPE.NET_TYPE_2G_INT);
                cityListTD = HttpUtil.getProvinceFtpInfoAdapter(CityInfoActivity.this,
                        provinceCode, MyCommonConstant.NET_TYPE.TD_INT);
                handler.sendEmptyMessage(refresh);
            };
        }.start();
    }

    private Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (refresh == msg.what) {
                setLayoutData();
                setListViewData(true);
                setCurrentProviceHigltShow(null);
                if (dialog != null && dialog.isShowing()) {
                    dialog.dismiss();
                }
            } else if (showLoadDialog == msg.what) {
                if (dialog != null && !dialog.isShowing()) {
                    dialog.show();
                }
            }
        };
    };

    private OnClickListener onclick = new OnClickListener() {
        @SuppressWarnings("unchecked")
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_left:
                    finish();
                    break;
                case R.id.btn_right:
                    if (isShare) {
                        String shareData = setShareData();
                        if (isShareData) {
                            try {
                                MyCommonUtil.share(CityInfoActivity.this,
                                        getString(R.string.share), shareData);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        isShare = false;
                    } else {
                        cbSelect.setChecked(false);
                        if (cityAdapter.getCount() > 0)
                            cityAdapter.setAllSelect(false);
                        isShare = true;
                    }
                    shareLayout();
                    setCurrentProviceHigltShow(null);
                    break;
                case R.id.tvTD2G:
                    if (isShowTdData) {
                        if (is2gtd) {

                            Collections.sort(itemlist, new SortCityStringSpeed(
                                    SortCityStringSpeed.DOWN, SortCityStringSpeed.cityTDSort));
                            tvTD2G.setText(getString(R.string.city_top_fix_speed)
                                    + getString(R.string.sortup));
                            is2gtd = false;
                        } else {
                            Collections.sort(itemlist, new SortCityStringSpeed(
                                    SortCityStringSpeed.UP, SortCityStringSpeed.cityTDSort));
                            tvTD2G.setText(getString(R.string.city_top_fix_speed)
                                    + getString(R.string.sortdown));

                            is2gtd = true;
                        }
                    } else {
                        if (is2gtd) {
                            Collections.sort(itemlist, new SortCityStringSpeed(
                                    SortCityStringSpeed.DOWN, SortCityStringSpeed.city2GSort));
                            tvTD2G.setText(getString(R.string.city_top_fix_speed)
                                    + getString(R.string.sortup));
                            is2gtd = false;
                        } else {
                            Collections.sort(itemlist, new SortCityStringSpeed(
                                    SortCityStringSpeed.UP, SortCityStringSpeed.city2GSort));
                            tvTD2G.setText(getString(R.string.city_top_fix_speed)
                                    + getString(R.string.sortdown));

                            is2gtd = true;
                        }
                    }
                    tvDropRate.setText(getString(R.string.city_top_slide_drop_rate));
                    tvSignal.setText(getString(R.string.city_top_slide_signal));
                    noticeDataChange();
                    break;
                // case R.id.tvFrequency:
                // if (isfre) {
                // Collections.sort(itemlist, new
                // SortCityIntSpeed(SortCityIntSpeed.UP,
                // SortCityIntSpeed.electricalLevel));
                // tvFrequency.setText(getString(R.string.frequency)
                // + getString(R.string.sortdown));
                // isfre = false;
                // } else {
                // Collections.sort(itemlist, new
                // SortCityIntSpeed(SortCityIntSpeed.DOWN,
                // SortCityIntSpeed.electricalLevel));
                // tvFrequency.setText(getString(R.string.frequency)
                // + getString(R.string.sortup));
                // isfre = true;
                // }
                // noticeDataChange();
                // break;
                case R.id.tvDropRate:
                    if (isdrop) {
                        Collections.sort(itemlist, new SortCityIntSpeed(SortCityIntSpeed.UP,
                                SortCityIntSpeed.droppingRate));
                        tvDropRate.setText(getString(R.string.city_top_slide_drop_rate)
                                + getString(R.string.sortup));
                        isdrop = false;
                    } else {
                        Collections.sort(itemlist, new SortCityIntSpeed(SortCityIntSpeed.DOWN,
                                SortCityIntSpeed.droppingRate));
                        tvDropRate.setText(getString(R.string.city_top_slide_drop_rate)
                                + getString(R.string.sortdown));
                        isdrop = true;
                    }
                    if (isShowTdData) {
                        tvTD2G.setText(getString(R.string.city_top_fix_speed));
                    } else {
                        tvTD2G.setText(getString(R.string.city_top_fix_speed));
                    }
                    tvSignal.setText(getString(R.string.city_top_slide_signal));
                    noticeDataChange();
                    break;
                case R.id.tvSignal:
                    if (isSignal) {
                        Collections.sort(itemlist, new SortCityIntSpeed(SortCityIntSpeed.UP,
                                SortCityIntSpeed.signalStrength));
                        tvSignal.setText(getString(R.string.city_top_slide_signal)
                                + getString(R.string.sortup));
                        isSignal = false;
                    } else {
                        Collections.sort(itemlist, new SortCityIntSpeed(SortCityIntSpeed.DOWN,
                                SortCityIntSpeed.signalStrength));
                        tvSignal.setText(getString(R.string.city_top_slide_signal)
                                + getString(R.string.sortdown));
                        isSignal = true;
                    }
                    if (isShowTdData) {
                        tvTD2G.setText(getString(R.string.city_top_fix_speed));
                    } else {
                        tvTD2G.setText(getString(R.string.city_top_fix_speed));
                    }
                    tvDropRate.setText(getString(R.string.city_top_slide_drop_rate));
                    noticeDataChange();
                    break;
                case R.id.tvComplete:
                    if (isComplete) {
                        isComplete = false;
                    } else {
                        isComplete = true;
                    }
                    noticeDataChange();
                    break;
            }
        }

    };

    private String setShareData() {
        StringBuffer sb = new StringBuffer();
        isShareData = false;
        if (cbInfoSelect.isChecked()) {
            isShareData = true;
            if (showAllInfo == null || showAllInfo.equals(""))
                sb.append(getString(R.string.bottom_country));
            else
                sb.append(Html.fromHtml(showAllInfo));
        }
        sb.append("\n");
        for (int i = 0; i < itemlist.size(); i++) {
            if (cityAdapter.isSelected(i)) {
                isShareData = true;
                sb.append(itemlist.get(i).getCity_name());
                sb.append(" ");
                if (isShowTdData) {
                    sb.append(getString(R.string.netTD));
                    sb.append(":");
                    sb.append(itemlist.get(i).getDownSpeed());
                } else {
                    sb.append(getString(R.string.net2G));
                    sb.append(":");
                    sb.append(itemlist.get(i).getDownSpeed());
                }
                sb.append(";");

                sb.append(getString(R.string.city_top_slide_signal));
                sb.append(":");
                sb.append(itemlist.get(i).getSignalStrength());
                sb.append(";");

                sb.append(getString(R.string.city_top_slide_call_complete));
                sb.append(":");
                sb.append(itemlist.get(i).getComRate());
                sb.append(";");

                sb.append(getString(R.string.city_top_slide_drop_rate));
                sb.append(":");
                sb.append(itemlist.get(i).getDroppingRate());
                sb.append(";");

                sb.append("\n");
            }
        }
        sb.append("--" + getString(R.string.app_name));
        return sb.toString();
    }

    private OnItemClickListener onItemClickListener = new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (isShare) {
                cityAdapter.setRadioSelect(arg2);
            } else {
                ((CheckBox) findViewById(R.id.cbStretch)).setChecked(false);
                if (provinceCode.equals(MyCommonConstant.FJ_PROVINCE_CODE)) {
                    Intent it = new Intent(CityInfoActivity.this, GridInfoActivity.class);
                    String currentUserClickCity = itemlist.get(arg2).getCity_name();
                    NetworkTestApp.getApp().setCurrentUserClickCity(currentUserClickCity);
                    it.putExtra(MyCommonConstant.CITY_NAME, currentUserClickCity);
                    it.putExtra(MyCommonConstant.CITY_CODE, itemlist.get(arg2).getCity_code());
                    // it.putExtra(MyCommonConstant.PROVINCE_CODE,provinceCode);
                    startActivity(it);
                } else {
                    Intent it = new Intent(CityInfoActivity.this, CellInfoActivity.class);
                    String currentUserClickCity = itemlist.get(arg2).getCity_name();
                    NetworkTestApp.getApp().setCurrentUserClickCity(currentUserClickCity);
                    it.putExtra(MyCommonConstant.CITY_NAME, currentUserClickCity);
                    it.putExtra(MyCommonConstant.CITY_CODE, itemlist.get(arg2).getCity_code());
                    it.putExtra(MyCommonConstant.PROVINCE_CODE, provinceCode);
                    startActivity(it);
                }
            }
        }
    };

    private OnScrollListener scrollListener = new OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            // TODO Auto-generated method stub
            switch (view.getId()) {
                case R.id.listViewRank:
                    if (lyStretch.getVisibility() == View.VISIBLE)
                        ((CheckBox) findViewById(R.id.cbStretch)).setChecked(false);
                    break;
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
            // TODO Auto-generated method stub

        }
    };

    private OnCheckedChangeListener onCheckedListener = new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            switch (buttonView.getId()) {
                case R.id.cbInfoSelect:
                    break;
                case R.id.cbSelect:
                    if (cityAdapter.getCount() > 0)
                        cityAdapter.setAllSelect(isChecked);
                    break;
                case R.id.rbNetTD:
                    if (isChecked) {
                        setListViewData(true);
                    }
                    break;
                case R.id.rbNet2G:
                    if (isChecked) {
                        setListViewData(false);
                    }
                    break;
                case R.id.cbStretch:
                    if (isChecked) {
                        lyStretch.setVisibility(View.VISIBLE);
                        ly_first.setVisibility(View.GONE);
                    } else {
                        lyStretch.setVisibility(View.GONE);
                        ly_first.setVisibility(View.VISIBLE);
                    }
                    break;
            }
        }
    };

    private OnClickListener onClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.ly_layout:
                    if (lyStretch.getVisibility() == View.GONE)
                        ((CheckBox) findViewById(R.id.cbStretch)).setChecked(true);
                    else
                        ((CheckBox) findViewById(R.id.cbStretch)).setChecked(false);
                    break;
                case R.id.allcontent:
                    if (lyStretch.getVisibility() == View.GONE)
                        ((CheckBox) findViewById(R.id.cbStretch)).setChecked(true);
                    else
                        ((CheckBox) findViewById(R.id.cbStretch)).setChecked(false);
                    break;
                case R.id.firstcontent:
                    if (lyStretch.getVisibility() == View.GONE)
                        ((CheckBox) findViewById(R.id.cbStretch)).setChecked(true);
                    else
                        ((CheckBox) findViewById(R.id.cbStretch)).setChecked(false);
                    break;
            }
        }
    };

    /**
     * 设置当前省份高亮显示。
     */
    private void setCurrentProviceHigltShow(Intent intent) {
        if (intent != null) {
            currentCityName = intent.getStringExtra(LocationConstant.CIRY);
        }
        if (currentCityName == null) {
            currentCityName = NetworkTestApp.getApp().getCityName();
        }

        // 到这边都是来自定位的数据，如果是北京，那么就不定位
        if (currentCityName != null) {
            if (currentCityName.equals(NetworkTestApp.getApp().getBeijing())) {
                currentCityName = null;
            }
        }
        // 说明已经有用户点击，那么当前高亮要使用用来最近一次点击的省份
        String click = NetworkTestApp.getApp().getCurrentUserClickCity();
        if (click != null) {
            currentCityName = click;
        }
        if (currentCityName != null) {
            pos = cityAdapter.setSelectShowItemt(currentCityName);

            if (pos >= 0) {
                cityAdapter.setRadio(pos);
                cityAdapter.notifyDataSetChanged();// 这个不能用noticeDataChange()替换，要不然会死循环
                // 由于要把当前省份显示在中间
                if (pos > 2) {
                    pos = pos - 2;
                } else {
                    pos = 0;
                }
                listViewRank.setSelection(pos);
            }
        }
    }

    /**
     * 由于网络变化，而触发的刷新。
     * 
     * @param isConnect
     */
    @Override
    protected void refreshByNetworkChange(boolean isConnect) {

        if (mCountryBean != null) {
            if (isConnect) {
                String selfNetType = MyCommonUtil.getNetWorkName(this);
                mCountryBean.setSelfNetType(selfNetType);

            } else {
                mCountryBean.setSelfNetType("");
            }
        }
    }

    @Override
    protected void locationSuccess(Intent intent) {
        setCurrentProviceHigltShow(intent);
    }

    @Override
    public void refresh() {
        // CountryUtil.refreshNetDataService(this);
        dataInit();
    }

    public void onBackPressed() {
        if (isShare) {
            isShare = false;
            shareLayout();
        } else {
            super.onBackPressed();
        }
    }

    private void noticeDataChange() {
        cityAdapter.notifyDataSetChanged();
        setCurrentProviceHigltShow(null);
    }
}
